home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / bin / DXUtils / dmotest.chm / common.js < prev    next >
Text File  |  2001-10-08  |  4KB  |  144 lines

  1. // Hilites the text in the code sample
  2. // oStart - reference to start of block
  3. // sText - string to find and hilite
  4. function HiliteText(oStart, sText)
  5. {
  6.  
  7.     var oRng = document.body.createTextRange();
  8.     oRng.moveToElementText(oStart);
  9.     var oRngFixed = oRng.duplicate();
  10.  
  11.     if (typeof(HiliteText.tokens) == 'undefined')
  12.     {
  13.         HiliteText.tokens = new Array(1);
  14.     }
  15.     else
  16.     {
  17.         for (i = 0; i < HiliteText.tokens.length; i++)
  18.         {
  19.             if (HiliteText.tokens[i].m_sSectionID == oStart.id && HiliteText.tokens[i].m_sToken == sText)
  20.             {
  21.                 return;
  22.             }
  23.         }
  24.  
  25.         HiliteText.tokens.length++;
  26.     }
  27.  
  28.  
  29.     while (oRng.findText(sText, 1000000, 6) && oRngFixed.inRange(oRng)) 
  30.     {    
  31.         oRng.execCommand('bold');
  32.         oRng.collapse(false);
  33.     }
  34.  
  35.     HiliteText.tokens[HiliteText.tokens.length-1] = new CHilitedToken(oStart.id, sText);
  36.  
  37. }
  38.  
  39. // a tuple representing the id of the section and the token to be hilited
  40. // the object is stored in an array to prevent the code from running twice on the same section
  41. function CHilitedToken(sSectionID, sToken)
  42. {
  43.     this.m_sSectionID = sSectionID;
  44.     this.m_sToken = sToken;
  45. }
  46.  
  47.  
  48. // Toggles the display of the content contained within oCode
  49. // oCode - reference to code block
  50. // sToken - string to bolden
  51. function ToggleSample(oCode, sToken)
  52. {
  53.     if (ShowHideSection(window.event.srcElement, 'Sample Code'))
  54.     {
  55.         HiliteText(oCode, sToken);
  56.     }
  57. }
  58.  
  59. // If hidden, show. If shown, hide. Modify the caption of the element appropriately
  60. // Returns true if showing on return, false if hidden on return
  61. function ShowHideSection(oHead, sText)
  62. {
  63.     var bRet = false;
  64.     var oChild = document.all(oHead.getAttribute('child', false));
  65.  
  66.     if (typeof(oChild) == null)
  67.     {
  68.         return bRet;
  69.     }
  70.  
  71.     var sClass = oChild.className;
  72.     var sAction = "Show";
  73.     if (sClass == "collapsed")
  74.     {
  75.         sAction = "Hide";
  76.         bRet = true; // we'll be showing upon return, so return true
  77.     }
  78.  
  79.     sAction = sAction + ' ' + sText;
  80.     oChild.className = (sClass == "collapsed" ? "expanded" : "collapsed");
  81.     oHead.innerText = sAction;
  82.     return bRet;
  83. }
  84.  
  85. // Set the caption of the specified element
  86. // oElem - reference to element to modify. Typically a Hn
  87. // sCaption - New caption for the element
  88. // bShow - boolean indicating whether or not the element should be made visible
  89. function SetExpandableCaption(oElem, sCaption, bShow)
  90. {
  91.     oElem.innerText = sCaption;
  92.     if (bShow) oElem.style.display = 'inline';
  93. }
  94.  
  95. // Set the caption for the TOC menu, and fix up the href. IE4 only
  96. function SetTOC()
  97. {
  98.     return;
  99.     var sProjectRoot1 = "/ds/";
  100.     var sProjectRoot2 = "\\ds\\";
  101.     if (typeof(AM_ICP_mnuToc) != 'object'){
  102.         alert('\n\n\nMessage 001 generated by common.js script module in function SetTOC() .\n\n\nTable of  Contents menu is not properly set up.\nShow/Hide Contents menu was not detected.\n\n\n');
  103.         return;
  104.     }
  105.  
  106.     // build a string for the 'Show Contents' case
  107.     var sPath = location.pathname;
  108.     
  109.     var sMask = (location.href.indexOf('ttp://') > 0) ? sProjectRoot1 : sProjectRoot2;    
  110.     
  111.     if (sPath.lastIndexOf(sMask) < 0) // doc isn't located under proper project
  112.     {
  113.         AM_ICP_mnuToc.style.visibility = "hidden"; // in case the style sheet wasn't hooked up
  114.         alert('\n\n\nMessage 002 generated by common.js script module in function SetTOC() .\n\n\nCurrent project location does not match mask expected settings.\nCurrent project root settings:\n    sProjectRoot1: "' + sProjectRoot1 + '"\n        or\n    sProjectRoot2: "' + sProjectRoot2 + '"\n\n\n');
  115.         return;
  116.     }
  117.  
  118.     var iStart = sPath.lastIndexOf(sMask)+sMask.length;
  119.     sFramed = sPath.substring(0,sPath.lastIndexOf(sMask)) +
  120.              sMask+"c-frame.htm#" +
  121.              (sPath.substring(iStart) == "" ? "default.htm" : sPath.substring(iStart));
  122.     
  123.     if (window.top != self) 
  124.     {
  125.         if (window.top.frames.length > 1 && window.top.frames[0].name=="TOC") 
  126.         {
  127.             AM_ICP_mnuToc.innerText = " Hide Contents";
  128.             AM_ICP_mnuToc.href     = location.pathname;
  129.             AM_ICP_mnuToc.target     = "_top";
  130.         }
  131.     }
  132.     else 
  133.     {
  134.         AM_ICP_mnuToc.innerText = " Show Contents";
  135.         AM_ICP_mnuToc.href     = sFramed;
  136.     }
  137.  
  138.     AM_ICP_mnuToc.style.visibility = "visible";
  139. }
  140.  
  141. function resizeDocContents()
  142. {
  143.     ; // document resize event handler
  144. }